import {default as api} from '../../utils/api';
//获取重点档案树
export function getArchiveTreeList(opt) {
  opt.url = "/dolphin/catalog/queryCatalogs";
  APIData(opt);
};

//获取移动目录
export function queryRemoveCatalogs(opt) {
  opt.url = "/dolphin/catalog/queryRemoveCatalogs";
  APIData(opt);
};

//添加/编辑目录
export function operateCatalog(opt) {
  if(opt.type === 0){
    opt.url = "/dolphin/catalog/addCatalog";
  }
  if(opt.type === 1){
    opt.url = "/dolphin/catalog/renameCatalog";
  }
  APIData(opt);
};

//删除目录
export function deleteCatalog(opt) {
  opt.url = "/dolphin/catalog/delCatalog";
  APIData(opt);
}

//移动目录
export function moveCatalog(opt) {
  opt.url = "/dolphin/catalog/removeCatalog";
  APIData(opt);
}

//移动目录
export function getArchiveCard(opt) {
  opt.url = "/dolphin/catalog/queryCatalogDetail";
  APIData(opt);
}

//需要展示的属性值
export function getTargetCodes(opt) {
  opt.url = "/dolphin/target/queryTargetCodes";
  APIData(opt);
}

//保存属性值
export function saveArchiveCode(opt) {
  opt.url = "/dolphin/target/addTarget";
  APIListData(opt);
}

//获取孩子节点的id
export function getChildNodes(list,array,ids){
  for(let k in list){
    for(let i = 0; i<ids.length;i++){
      if(list[k].pId === ids[i]){
        array.push(list[k].id);
        ids.push(list[k].id);
      }
    }
    getChildNodes(list[k].children,array,ids);
  }
}
export function deleteCard(opt) {
  opt.url = "/dolphin/target/delTarget";
  APIData(opt);
}

export function batchDeleteCard(opt) {
  opt.url = "/dolphin/target/batchDelTarget";
  APIListData(opt);
}

export function getMovePersonTree(opt) {
  opt.url = "/dolphin/target/queryDeptUser";
  APIData(opt);
}

export function transferTarget(opt) {
  opt.url = "/dolphin/target/transferTarget";
  APIData(opt);
}
//分享树
export function getShareArchiveTree(opt) {
  opt.url = "/dolphin/target/queryAuthorizeTree";
  APIData(opt);
}

//保存属性值
export function saveShareTreeNode(opt) {
  opt.url = "/dolphin/target/shareTarget";
  APIListData(opt);
}

//保存移动目录
export function saveMoveTreeNode(opt) {
  opt.url = "/dolphin/target/moveTargetCatalog";
  APIListData(opt);
}

//params
function APIData(opt) {
  if(!opt.data){
    opt.data = '';
  }
  api({
    url: opt.url,
    method: "post",
    dataType:'json',
    params:opt.data,
    contentType: "application/json",
  }).then(resp => {
    if(opt.callback){
      opt.callback(resp);
    }
  });
}
//请求参数是data
function APIListData(opt) {
  if(!opt.data){
    opt.data = '';
  }
  api({
    url: opt.url,
    method: "post",
    dataType:'json',
    data:JSON.stringify(opt.data),
    contentType: "application/json",
  }).then(resp => {
    if(opt.callback){
      opt.callback(resp);
    }
  });
}
